#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int* replaceChars(char *string, char lookup, char replace) {
	int i = -1;
	int *result = NULL;
	int resultSize = 0;
	
	while (string[++i] != '\0') {
		if (string[i] == lookup) {
			resultSize++;
		}
	}
	i=-1;
	
	result = malloc(resultSize*sizeof(int));
	
	printf("string: %s\n", string);
	printf("string (char by char):\n\n");
	while (string[++i] != '\0') {
		printf("#%i: %c\n", i, string[i]);
		if (string[i] == lookup) {
			string[i] = replace;
			printf("#%i REPLACED\n", i);
			result[resultSize] = i;
		}
	}
	return result;
}

int main(void) {
	char *content, *name, *dirname, *pubDateParts;
	int i, length;
	int* pubDatePartsOffsets;
	char* pubDate = "Wed, 15 Dec 2010 12:00:00 +0100";
	// make a copy of the pubDate, split it into loose strings 
	pubDateParts = malloc((strlen(pubDate) + 1)*sizeof(char));
	strncpy(pubDateParts, pubDate, (strlen(pubDate) + 1)*sizeof(char));
	pubDatePartsOffsets = replaceChars(pubDateParts, ' ', '\0');
	// form the directory name from it in which the file should be placed
	// assuming pubDate was formatted like Wed, 15 Dec 2010 12:00:00 +0100
	// the format of dirname will be 2010-Dec, so:
	dirname = malloc(8*sizeof(char));
	printf("char_offset: %i\n", pubDatePartsOffsets[2]+1);
	// strncpy(dirname, &pubDateParts[pubDatePartsOffsets[2]+1], 4); // +1 because: see replaceChars return value
	// dirname[4] = '-';
	// strncpy(&dirname[5], &pubDateParts[pubDatePartsOffsets[1]+1], 3);
}

